home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-17 | 7.8 KB | 213 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: Geometry.lib
- #
- # Contains: xxx put contents here xxx
- #
- # Written by: Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
- #
- # Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # <1.0.3> 12/13/93 KTA Added task CenterPointOfRect()
- # <1+> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
- #########################################################################
- # PtInRect(thePoint,theRect)
- #========================================================================
- # Author: NJV
- # Description: This routine determines whether or not thePoint
- # is contained within theRect (including borders).
- # Parameters: thePoint - a list of two integers
- # theRect - holds the coordinates of the rectangle.
- # Returns: true - point lies in the rectangle.
- # false - point does NOT lie in the rectangle.
- # Examples: isIt := PtInRect(thePoint,theRect).
- # Assumptions: None
- #========================================================================
- # History:
- #
- #########################################################################
- TASK PtInRect(thePoint,theRect) begin
- return( ((thePoint[1] >= theRect[1]) and (thePoint[1] <= theRect[3]))
- and ((thePoint[2] >= theRect[2]) and (thePoint[2] <= theRect[4])) );
- end;
-
- ########################################################################
- # RndPtInWindow(specifier:=-1)
- #=======================================================================
- # Author: Nick Vaccaro
- # Description: Returns a random point inside of the window. If specifier
- # is not passed, it will return a random point of the
- # content region of the first window with a grow and a
- # zoom box, or if there are none, then the first window
- # it finds, and if no windows are present, returns 0.
- # Parameters: specifier - title or ordinality of window
- # Returns: 0 - couldn't find window
- # Point - list of 2 coordinates - {x,y}
- # Examples: thePoint := RndPtInWindow(); # get random point in window content
- # thePoint := RndPtInWindow(1); # random point in window ordinality 1
- #=======================================================================
- # History:
- #
- #########################################################################
- TASK RndPtInWindow(specifier:=-1) begin
- if (specifier = -1)
- return(RndPtInRect()); # return point in first window w/ size and zoom box
-
- if (TypeOf(specifier) = 'integer')
- there := match [window o:specifier]!;
- else
- there := match [window t:specifier]!;
-
- if (there)
- return(RndPtInRect(there.r)); # return random point in window's rect
- else
- return(0);
- end;
-
- ########################################################################
- # RndPtInRect(theRect)
- #=======================================================================
- # Author: Nick Vaccaro
- # Description: Returns a random point inside of theRect. If theRect
- # is not passed, it will return a random point of the
- # content region of the first window with a grow and a
- # zoom box, or if there are none, then the first window
- # it finds, and if no windows are present, returns 0.
- # Parameters: theRect - bounding rectangle
- # Returns: 0 - Default behavior requested with no windows up
- # Point - list of 2 coordinates - {x,y}
- # Examples: thePoint := RndPtInRect(); # get random point in window content
- # thePoint := RndPtInRect({20,20,80,80}); # random point in {20,20,80,80}
- # Assumptions: None
- #=======================================================================
- # History:
- #
- #########################################################################
- TASK RndPtInRect(theRect:=-1) begin
- if (theRect = -1) begin # use content rect of first window with grow and zoom box
- foo := match [window g:true z:true]!;
- if (foo)
- theRect := foo.r;
- else begin
- foo := match [window]!; # try to find any window
- if (not foo)
- return(0);
- else
- theRect := foo.r;
- end;
- end;
- x := Random(theRect[1],theRect[3]);
- y := Random(theRect[2],theRect[4]);
- return({x,y});
- end;
-
- #########################################################################
- # RectInRect(rect1,rect2)
- #========================================================================
- # Author: SMQ
- # Description: This routine determines whether or not first rectangle
- # lies completely within the second. This is done by
- # comparing the coordinates of both rectangles.
- # Parameters: rect1 - holds the coordinates of the first rectangle.
- # rect2 - holds the coordinates of the second rectangle.
- # Returns: value - first rectangle lies in the second.
- # false - first rectangle does NOT lie in the second.
- # Examples: RectInRect(rect1,rect2).
- # Assumptions: None
- #========================================================================
- # History:
- #
- #########################################################################
- TASK RectInRect(rect1, rect2) begin
-
- Left1 := rect1[1];
- Top1 := rect1[2];
- Right1 := rect1[3];
- Bottom1 := rect1[4];
-
- Left2 := rect2[1];
- Top2 := rect2[2];
- Right2 := rect2[3];
- Bottom2 := rect2[4];
-
- return (((Left2 <= Left1) and (Top2 <= Top1) and (Right2 >= Right1) and (Bottom2 >= Bottom1)));
- end;
-
-
- ########################################################################
- # GetXYRandom(inset, Rect, numPts)
- #=======================================================================
- # Author: SL
- # Description: Returns a random X and Y coordinate in the specified
- # Rect.
- # Parameters: inset - ltrb inset from scrn or window
- # specifier > 0 window to find coords in
- # = O coords in window with s:doc g:true and c:true
- # < 0 coords in specified screen. Screen numbersta
- # is negative of specifier.
- # Returns: xyRandom - List of random X and Y. eg. { x, y }
- #=======================================================================
- ########################################################################
- TASK GetXYRandom(inset := { 0,0,0,0}, Rect := {}, numPts := 1)
- begin
- pointlist := {};
- if not (Rect)
- match[screen m:1 r:?Rect];
- if (rect)
- begin
- maxX := rect[3] - rect[1] - inset[3];
- maxY := rect[4] - rect[2] - inset[4];
- for i := 1 to numPts
- begin
- xRandom := random(inset[1], maxX);
- yRandom := random(inset[2], maxY);
-
- thePoint := { xRandom, yRandom };
- if(numPts > 1) # Do we want a point list
- pointList := insert(thePoint , i, pointList );
- end;
- if(numPts = 1) # If there is only one return it just like we always have
- returnVal := thePoint;
- else # Otherwise return a list of points { {xPt,yPt},{xPt2, yPt2} };
- returnVal := pointList;
- end;
- else
- returnVal := 0;
- return(returnVal);
- end; # getXYRandom()
-
-
- ########################################################################
- # CenterPointOfRect(pTheRect)
- #=======================================================================
- # Author: Kevin Avoy
- # Description: Returns the center point of the input parameter <pTheRect>
- # Parameters: pTheRect - the rect that you want the center point of.
- # Returns: returnVal - List { x, y }
- #=======================================================================
- # History:
- # KTA 12/13/93 Created
- ########################################################################
- TASK CenterPointOfRect(pTheRect := {})
- begin
- returnVal := 0;
- if(pTheRect)
- begin
- x := ((pTheRect[3] + pTheRect[1])/2);
- y := ((pTheRect[4] + pTheRect[2])/2);
-
- returnVal := {x,y};
- end;
- return(returnVal);
- end;